package org.shj.thread.book2.chapter03;

import java.util.Random;

public class ServerThread extends Thread{
	private Random random;
	private RequestQueue requestQueue;
	
	public ServerThread(RequestQueue requestQueue, String name, long seed){
		super(name);
		this.requestQueue = requestQueue;
		this.random = new Random(seed);
	}
	
	public void run(){
//		try{
		for(int i = 0; i < 100; i++){
			Request req = requestQueue.getRequest();
			System.out.println(Thread.currentThread().getName() + " get: " + req);
			try{
				Thread.sleep(random.nextInt(1000));
			}catch(InterruptedException e){
				
			}
		}
//		}catch(InterruptedException e){
//			
//		}
	}
}
